/*
 * Copyright(c) 2018-? the original author[Wien(luweien@aliyun.com)] or authors.
 *
 */
package org.doll.it.web.auditor;

import java.util.Optional;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.domain.AuditorAware;
import org.springframework.data.mongodb.config.EnableMongoAuditing;

@Configuration
@ConditionalOnProperty(name = "doll.web.auditor.enabled", havingValue = "true", matchIfMissing = true)
@Import(AuditorAware.class)
public class DollMongoAuditorAutoConfig {

	@Bean
	@ConditionalOnMissingBean(AuditorAware.class)
	public AuditorAware<Long> currentAuditorProvider() {
		return new DefaultOperatorAuditor();
	}

	/**
	 * 开启Mongodb的Auditor
	 * @author Wien(luweien@aliyun.com)
	 */
	@EnableMongoAuditing
	public class DefaultOperatorAuditor implements AuditorAware<Long> {

		@Override
		public Optional<Long> getCurrentAuditor() {
			//TODO get current user id
			return Optional.of(175876L);
		}

	}
}
